home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / flying-6.11 / pool.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  4.2 KB  |  171 lines

  1. #ifndef _global_h
  2. #    include "global.h"
  3. #endif
  4.  
  5. #ifndef _pool_h
  6. #    include "pool.h"
  7. #endif
  8. #ifndef _pcon_h
  9. #    include "pcon.h"
  10. #endif
  11. #ifndef _pocket_h
  12. #    include "pocket.h"
  13. #endif
  14. #ifndef _wall_h
  15. #    include "wall.h"
  16. #endif
  17. #ifndef _graph_h
  18. #    include "graph.h"
  19. #endif
  20. #ifndef _mover_h
  21. #    include "mover.h"
  22. #endif
  23. #ifndef _keeper_h
  24. #    include "keeper.h"
  25. #endif
  26.  
  27.  
  28. //
  29. // Voreinstellungen
  30. //
  31.  
  32.  
  33. const int  Pool::nPockets        = 6;
  34.  
  35.  
  36. const Real & Pool::GetNormalBallSize() const {
  37.     return BallRadius;
  38. }
  39.  
  40. void Pool::InitArea( double wx, double wy ) {
  41.     area_width  = wx;
  42.     area_height = wy;
  43.     if (area_width/2.>area_height)   area_height = area_width/2.;
  44.     else                             area_width  = area_height*2.;
  45.     area_off_x = (MaxX()-area_width)/2.;
  46.     area_off_y = (MaxY()-PocketHeight-area_height)/2.;
  47. }
  48.  
  49. int Pool::SelectTable( int col ) {
  50.     col = Billard::SelectTable(col);
  51.     pocket_col  = CreateColorMix( 0, table_line_col );
  52.     return col;
  53. }
  54.  
  55. Pool::Pool(double wx, double wy) :
  56. Billard(wx,wy+PocketHeight)
  57. {
  58.     InitArea(wx,wy);
  59.     pcon = 0;
  60.     for (int i=0;i<nPockets;i++)         p[i] = 0;
  61.  
  62. // SetMainBgColor( "SeaGreen" );        // GlobalBackground
  63.     cue_col        = AddBallColor( "ivory" );
  64.     pocket_col  = CreateColorMix( 0, table_line_col );
  65.  
  66.     keeper = new LineKeeper(PocketHeight,PocketFrame,inner_cushion_col,table_col);
  67.  
  68.     cue_in_pocket = 0;
  69. }
  70.  
  71. Pool::~Pool() {
  72.     if (pcon)        delete [] pcon;
  73.     for (int i=0;i<6;i++)        if (p[i])    delete p[i];
  74. }
  75.  
  76.  
  77. void Pool::InitTable( double rad ) {
  78.     po = PocketRadius/sqrt(2);
  79. //    po=0;
  80.  
  81.     p[0] = new Pocket( PAreaOffX()+po,                     PAreaOffY()+po, PocketRadius );
  82.     p[1] = new Pocket( PAreaOffX()+PAreaWidth()/2.,  PAreaOffY()+po, PocketRadius );
  83.     p[2] = new Pocket( PAreaOffX()+PAreaWidth()-po, PAreaOffY()+po, PocketRadius );
  84.     p[3] = new Pocket( PAreaOffX()+PAreaWidth()-po, PAreaOffY()+PAreaHeight()-po,
  85.                                                                                 PocketRadius );
  86.     p[4] = new Pocket( PAreaOffX()+PAreaWidth()/2.,    PAreaOffY()+PAreaHeight()-po,
  87.                                                                                 PocketRadius );
  88.     p[5] = new Pocket( PAreaOffX()+po,                    PAreaOffY()+PAreaHeight()-po,
  89.                                                                                 PocketRadius );
  90.  
  91.     pcon = new PocketConnector[nPockets];
  92.     pcon[0].Init( *p[0], EdgeAngle, *p[1],  MidAngle, InnerCushion-po, rad );
  93.     pcon[1].Init( *p[1],  MidAngle, *p[2], EdgeAngle, InnerCushion-po, rad );
  94.     pcon[2].Init( *p[2], EdgeAngle, *p[3], EdgeAngle, InnerCushion-po, rad );
  95.     pcon[3].Init( *p[3], EdgeAngle, *p[4],  MidAngle, InnerCushion-po, rad );
  96.     pcon[4].Init( *p[4],  MidAngle, *p[5], EdgeAngle, InnerCushion-po, rad );
  97.     pcon[5].Init( *p[5], EdgeAngle, *p[0], EdgeAngle, InnerCushion-po, rad );
  98. }
  99.  
  100.  
  101. void Pool::InitPlayground() {
  102.     Billard::InitPlayground();
  103.     BallRadius = m->GetActRadius();
  104.  
  105.     InitTable();
  106. }
  107.  
  108. void Pool::DrawBackground() const {
  109.     Billard::DrawBackground();
  110.  
  111. // Undraw middle marker
  112.     SetBgColor( outer_cushion_col );
  113.     double    outer = PAreaOffY()-TAreaOffY();
  114.     int        i=4;
  115.     DrawMarker( AreaOffX()+AreaWidth()*Real(i)/8., TAreaOffY()+outer/2.,
  116.                                                                         outer/8., outer/4. );
  117.     DrawMarker( AreaOffX()+AreaWidth()*Real(i)/8., TAreaOffY()+TAreaHeight()-outer/2.,
  118.                                                                         outer/8., outer/4. );
  119.  
  120. // Draw Pockets
  121.     for (i=0;i<nPockets;i++) {
  122.         SetBgColor( table_col );
  123.         FillPoly(4, &pcon[i].w1->p1, &pcon[i].w2->p1,
  124.                         &pcon[(i+nPockets-1)%nPockets].w2->p2,
  125.                         &pcon[(i+nPockets-1)%nPockets].w3->p2 );
  126.         SetBgColor(pocket_col);
  127.         FillCircle( p[i]->P(), p[i]->R() );
  128.     }
  129.     for (i=0;i<nPockets;i++) {
  130.         SetBgColor(inner_cushion_col);
  131.         FillArc( pcon[i].b1->p, pcon[i].b1->r, pcon[i].b1->start, pcon[i].b1->angle );
  132.         FillArc( pcon[i].b2->p, pcon[i].b2->r, pcon[i].b2->start, pcon[i].b2->angle );
  133.         FillPoly(6,    &pcon[i].w1->p1, &pcon[i].w1->p2,
  134.                         &pcon[i].w2->p1, &pcon[i].w2->p2,
  135.                         &pcon[i].w3->p1, &pcon[i].w3->p2    );
  136.     }
  137. }
  138.  
  139.  
  140. //////////////////////////////////////////////////////////////////////////////
  141.  
  142. void Pool::InPocket( Ball *b ) {
  143.     Billard::InPocket(b);
  144.     if (b==cueball)    cue_in_pocket = 1;
  145. }
  146.  
  147. void Pool::AllBallsStopped() {
  148.     Billard::AllBallsStopped();
  149.     (void)IsSelectable(cueball);        // back on the table
  150. }
  151.  
  152. int Pool::IsSelectable(Ball *b) {
  153.     if (b==cueball) {
  154.         if (cue_in_pocket) {
  155.             Vec2    newpos;
  156.  
  157.             b->FitsNextTo(cuedef,Vec2(-1.0,RealZero),&newpos);
  158.             cue_in_pocket = 0;
  159.             b->SetP(newpos);
  160.             b->ChgV(Vec2Zero);
  161.  
  162.             return 0;
  163.         }
  164.         else {
  165.             return 1;
  166.         }
  167.     }
  168.  
  169.     return Billard::IsSelectable(b);
  170. }
  171.